using Circus.CodeEditor;
using Circus.CodeEditor.TextSource;
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace Circus.CodeEditor.Dialogs
{
	public class DlgSearch : Form
	{
		private const int defaultOptionsHeight = 142;
		private const int defaultOptionsTop = 80;
		private const int defaultOptionsReplaceTop = 126;
		private const int defaultButtonsHeigth = 36;
		private const int defaultOptionsClosedHeight = 12;
		private const int defaultButtonsReplaceHeigth = 65;
		private bool isReplace;
		private CodeEditor search;
		private bool findTextAtCursor;
		private SearchOptions options;
		private bool clearBookmarks;
		private bool firstSearch = true;
		private SearchOptions saveOptions;
		private string saveText = string.Empty;
		private bool optionsVisible = false;
		private bool selectionEnabled = false;
		private IContainer components = null;
		public CheckBox chbPromptOnReplace;
		public CheckBox chbSearchUp;
		public CheckBox chbSearchHiddenText;
		public CheckBox chbMatchWholeWord;
		public Button btReplacePopup;
		public CheckBox chbMatchCase;
		public CheckBox chbUseRegularExpressions;
		private ContextMenu cmReplace;
		private MenuItem miFindWhatText;
		private MenuItem miTaggedExpression1;
		private MenuItem miTaggedExpression2;
		private MenuItem miTaggedExpression3;
		private MenuItem miTaggedExpression4;
		private MenuItem miTaggedExpression5;
		private MenuItem miTaggedExpression6;
		private MenuItem miTaggedExpression7;
		private MenuItem miTaggedExpression8;
		private MenuItem miTaggedExpression9;
		public MenuItem miTag;
		public Label laFindWhat;
		public ComboBox cbReplaceWith;
		public Label laReplaceWith;
		public MenuItem miEscape;
		public Button btReplaceAll;
		public Button btMarkAll;
		public Button btReplace;
		public Button btFindNext;
		public ContextMenu cmFind;
		public MenuItem miSingleChar;
		public MenuItem miZeroOrMore;
		public MenuItem miOneOrMore;
		public MenuItem menuItem4;
		public MenuItem miBeginLine;
		public MenuItem miEndLine;
		private MenuItem miLineBreak;
		public MenuItem menuItem10;
		public MenuItem miOneCharInSet;
		public MenuItem miOneCharNotInSet;
		public MenuItem miOr;
		public Button btPopup;
		public ComboBox cbFindWhat;
		private Panel pnButtons;
		private GroupBox gbFindOptions;
		public Button btClose;
		private ComboBox cbLookIn;
		public Label laLookIn;
		public Button btFindOptions;
		private Label laFindOptions;
		private Panel pnFindOptions;
		private TabPage tbUseFind;
		private TabPage tbUseReplace;
		private ImageList imSearch;
		public TabControl tbSearch;
		protected virtual bool FirstSearch
		{
			get
			{
				return this.SearchShared ? SearchManager.SharedSearch.FirstSearch : this.search.FirstSearch;
			}
		}
		protected virtual bool SearchShared
		{
			get
			{
				return SearchManager.SharedSearch.Shared;
			}
			set
			{
				if (SearchManager.SharedSearch.Shared != value)
				{
					SearchManager.SharedSearch.Shared = value;
					SearchManager.SharedSearch.Init(ref this.search, this.Options);
				}
			}
		}
		public CodeEditor Search
		{
			get
			{
				return this.SearchShared ? SearchManager.SharedSearch.Search : this.search;
			}
			set
			{
				this.search = value;
			}
		}
		public SearchOptions Options
		{
			get
			{
				SearchOptions searchOptions = (this.chbMatchCase.Checked ? SearchOptions.CaseSensitive : SearchOptions.None) | (this.chbMatchWholeWord.Checked ? SearchOptions.WholeWordsOnly : SearchOptions.None) | (this.chbSearchHiddenText.Checked ? SearchOptions.SearchHiddenText : SearchOptions.None) | (this.chbSearchUp.Checked ? SearchOptions.BackwardSearch : SearchOptions.None) | (this.chbUseRegularExpressions.Checked ? SearchOptions.RegularExpressions : SearchOptions.None) | (this.findTextAtCursor ? SearchOptions.FindTextAtCursor : SearchOptions.None) | (this.chbPromptOnReplace.Checked ? SearchOptions.PromptOnReplace : SearchOptions.None) | (((this.options & SearchOptions.FindSelectedText) != SearchOptions.None) ? SearchOptions.FindSelectedText : SearchOptions.None) | (((this.options & SearchOptions.CycledSearch) != SearchOptions.None) ? SearchOptions.CycledSearch : SearchOptions.None) | (((this.options & SearchOptions.SilentSearch) != SearchOptions.None) ? SearchOptions.SilentSearch : SearchOptions.None);
				if (this.search != null && this.search.SearchGlobal)
				{
					searchOptions |= (((this.cbLookIn.SelectedIndex == 1) ? SearchOptions.AllDocuments : SearchOptions.None) | ((this.cbLookIn.SelectedIndex == 2) ? SearchOptions.CurrentProject : SearchOptions.None) | ((this.cbLookIn.SelectedIndex == 3) ? SearchOptions.EntireScope : SearchOptions.None) | ((this.cbLookIn.SelectedIndex == 4) ? SearchOptions.SelectionOnly : SearchOptions.None));
				}
				else
				{
					searchOptions |= (((this.cbLookIn.SelectedIndex == 1) ? SearchOptions.EntireScope : SearchOptions.None) | ((this.cbLookIn.SelectedIndex == 2) ? SearchOptions.SelectionOnly : SearchOptions.None));
				}
				if ((searchOptions & SearchOptions.SelectionOnly) != SearchOptions.None)
				{
					if ((this.options & SearchOptions.AllDocuments) != SearchOptions.None)
					{
						searchOptions |= SearchOptions.AllDocuments;
					}
					if ((this.options & SearchOptions.CurrentProject) != SearchOptions.None)
					{
						searchOptions |= SearchOptions.CurrentProject;
					}
					if ((this.options & SearchOptions.EntireScope) != SearchOptions.None)
					{
						searchOptions |= SearchOptions.EntireScope;
					}
				}
				return searchOptions;
			}
			set
			{
				this.options = value;
				this.UpdateSearch();
				this.chbMatchCase.Checked = ((value & SearchOptions.CaseSensitive) != SearchOptions.None);
				this.chbMatchWholeWord.Checked = ((value & SearchOptions.WholeWordsOnly) != SearchOptions.None);
				this.chbSearchHiddenText.Checked = ((value & SearchOptions.SearchHiddenText) != SearchOptions.None);
				this.chbSearchUp.Checked = ((value & SearchOptions.BackwardSearch) != SearchOptions.None);
				this.chbUseRegularExpressions.Checked = ((value & SearchOptions.RegularExpressions) != SearchOptions.None);
				if (this.search != null && this.search.SearchGlobal)
				{
					if ((value & SearchOptions.AllDocuments) != SearchOptions.None)
					{
						this.cbLookIn.SelectedIndex = 1;
					}
					else
					{
						if ((value & SearchOptions.CurrentProject) != SearchOptions.None)
						{
							this.cbLookIn.SelectedIndex = 2;
						}
						else
						{
							if ((value & SearchOptions.EntireScope) != SearchOptions.None)
							{
								this.cbLookIn.SelectedIndex = 3;
							}
						}
					}
					if ((value & SearchOptions.SelectionOnly) != SearchOptions.None)
					{
						this.cbLookIn.SelectedIndex = ((this.cbLookIn.Items.Count > 4) ? 4 : 0);
					}
				}
				else
				{
					if ((value & SearchOptions.EntireScope) != SearchOptions.None)
					{
						this.cbLookIn.SelectedIndex = 1;
					}
					if ((value & SearchOptions.SelectionOnly) != SearchOptions.None)
					{
						this.cbLookIn.SelectedIndex = ((this.cbLookIn.Items.Count > 2) ? 2 : 0);
					}
				}
				this.btPopup.Enabled = this.chbUseRegularExpressions.Checked;
				this.findTextAtCursor = ((value & SearchOptions.FindTextAtCursor) != SearchOptions.None);
				this.chbPromptOnReplace.Checked = ((value & SearchOptions.PromptOnReplace) != SearchOptions.None);
			}
		}
		public bool SelectionEnabled
		{
			get
			{
				return this.selectionEnabled;
			}
			set
			{
				this.selectionEnabled = value;
			}
		}
		public bool IsReplace
		{
			get
			{
				return this.isReplace;
			}
			set
			{
				if (this.isReplace != value)
				{
					this.isReplace = value;
					this.ReplaceChanged();
				}
			}
		}
		public bool OptionsVisible
		{
			get
			{
				return this.optionsVisible;
			}
			set
			{
				this.optionsVisible = value;
			}
		}
		public bool ClearBookmarks
		{
			get
			{
				return this.clearBookmarks;
			}
			set
			{
				this.clearBookmarks = value;
			}
		}
		public DlgSearch()
		{
			this.InitializeComponent();
		}
		private RegexOptions GetRegexOptions(string text)
		{
			return (this.chbSearchUp.Checked ? RegexOptions.RightToLeft : RegexOptions.None) | ((!this.chbMatchCase.Checked) ? RegexOptions.IgnoreCase : RegexOptions.None) | ((text != null && (text.IndexOf("\\r") >= 0 || text.IndexOf("\\n") >= 0)) ? RegexOptions.Multiline : RegexOptions.None);
		}
		private bool IsEscapeChar(string s, int index)
		{
			bool flag = false;
			while (index > 0 && s[index - 1] == '\\')
			{
				if (s[index - 1] == '\\')
				{
					flag = !flag;
				}
				index--;
			}
			return flag;
		}
		private void RemoveChar(ref string s, char ch)
		{
			for (int i = s.Length - 1; i > 0; i--)
			{
				if (s[i] == ch && this.IsEscapeChar(s, i))
				{
					s = s.Remove(i - 1, 2);
				}
			}
		}
		private void ReplaceChar(ref string s, char ch, string replace)
		{
			for (int i = s.Length - 1; i > 0; i--)
			{
				if (s[i] == ch && this.IsEscapeChar(s, i))
				{
					s = s.Remove(i - 1, 2);
					if (replace != string.Empty)
					{
						s = s.Insert(i - 1, replace);
					}
				}
			}
		}
		private void FixCarriageReturn(ref string s)
		{
			this.ReplaceChar(ref s, 'r', string.Empty);
			this.ReplaceChar(ref s, 'n', "\\r\\n");
		}
		private Regex GetExpression()
		{
			Regex result = null;
			if (this.chbUseRegularExpressions.Checked)
			{
				try
				{
					string text = this.cbFindWhat.Text;
					this.FixCarriageReturn(ref text);
					result = new Regex(text, this.GetRegexOptions(this.cbFindWhat.Text));
				}
				catch (Exception exception)
				{
					result = null;
					ErrorHandler.Error(exception);
				}
			}
			return result;
		}
		private void AddToHistory(IList List, string s)
		{
			if (s != string.Empty)
			{
				for (int i = List.IndexOf(s); i >= 0; i = List.IndexOf(s))
				{
					List.RemoveAt(i);
				}
				List.Insert(0, s);
			}
		}
		private void AddToHistory()
		{
			if (this.cbFindWhat.Text != string.Empty)
			{
				this.AddToHistory(this.cbFindWhat.Items, this.cbFindWhat.Text);
				this.cbFindWhat.SelectedIndex = 0;
			}
			if (this.isReplace && this.cbReplaceWith.Text != string.Empty)
			{
				this.AddToHistory(this.cbReplaceWith.Items, this.cbReplaceWith.Text);
				this.cbReplaceWith.SelectedIndex = 0;
			}
		}
		private void TextFound()
		{
			this.firstSearch = false;
			this.saveOptions = this.Options;
			this.saveText = this.cbFindWhat.Text;
		}
		private void btPopup_Click(object sender, EventArgs e)
		{
			this.cmFind.Show((Control)sender, new Point(0, 0));
		}
		private void btFindNext_Click(object sender, EventArgs e)
		{
			this.AddToHistory();
			this.UpdateSearchMode();
			if (this.Search != null)
			{
				SearchOptions searchOptions = this.Options;
				bool flag;
				if (!this.FirstSearch && !this.firstSearch && this.cbFindWhat.Text == this.saveText && searchOptions == this.saveOptions)
				{
					if ((searchOptions & SearchOptions.BackwardSearch) != SearchOptions.None)
					{
						flag = this.FindPrevious();
					}
					else
					{
						flag = this.FindNext();
					}
				}
				else
				{
					flag = this.Find(this.cbFindWhat.Text, searchOptions, this.GetExpression());
				}
				if (flag)
				{
					this.TextFound();
				}
				else
				{
					this.ShowNotFound();
				}
			}
		}
		private void btReplace_Click(object sender, EventArgs e)
		{
			if (!this.isReplace)
			{
				this.IsReplace = true;
			}
			else
			{
				this.AddToHistory();
				this.UpdateSearchMode();
				if (this.Search != null)
				{
					Match match = null;
					SearchOptions searchOptions = this.Options;
					bool flag;
					if (!this.FirstSearch && this.cbFindWhat.Text == this.saveText && this.NeedReplaceCurrent(out match))
					{
						if (!this.ReplaceCurrent(this.cbReplaceWith.Text, searchOptions, match))
						{
							return;
						}
						if ((this.Options & SearchOptions.BackwardSearch) != SearchOptions.None)
						{
							flag = this.FindPrevious();
						}
						else
						{
							flag = this.FindNext();
						}
					}
					else
					{
						flag = this.Find(this.cbFindWhat.Text, searchOptions, this.GetExpression());
					}
					if (flag)
					{
						this.TextFound();
					}
					else
					{
						this.ShowNotFound();
					}
				}
			}
		}
		private void btReplaceAll_Click(object sender, EventArgs e)
		{
			this.AddToHistory();
			this.UpdateSearchMode();
			if (this.Search != null)
			{
				Match match = null;
				SearchOptions searchOptions = this.Options;
				if (!this.FirstSearch && this.cbFindWhat.Text == this.saveText && this.NeedReplaceCurrent(out match))
				{
					this.ReplaceCurrent(this.cbReplaceWith.Text, searchOptions, match);
				}
				int num;
				if (!this.ReplaceAll(this.cbFindWhat.Text, this.cbReplaceWith.Text, this.Options, this.GetExpression(), out num))
				{
					this.ShowNotFound();
				}
				else
				{
					MessageBox.Show(string.Format(StringConsts.OccurencesReplaced, num), this.Text);
				}
			}
		}
		private void btMarkAll_Click(object sender, EventArgs e)
		{
			if (this.Search != null)
			{
				this.MarkAll(this.cbFindWhat.Text, this.Options, this.GetExpression(), this.clearBookmarks);
			}
		}
		private void chbUseRegularExpressions_Click(object sender, EventArgs e)
		{
			this.btPopup.Enabled = this.chbUseRegularExpressions.Checked;
			this.btReplacePopup.Enabled = this.chbUseRegularExpressions.Checked;
		}
		private void miBeginWord_Click(object sender, EventArgs e)
		{
			string text = ((MenuItem)sender).Text.Trim();
			int num = text.IndexOf(' ');
			if (num > 0)
			{
				text = text.Substring(0, num);
			}
			this.cbFindWhat.Text = this.cbFindWhat.Text + text;
		}
		private void btFindOptions_Click(object sender, EventArgs e)
		{
			this.optionsVisible = !this.optionsVisible;
			this.ResizeControls();
		}
		private void ResizeControls()
		{
			float num = (float)this.Font.Height / (float)Control.DefaultFont.Height;
			this.gbFindOptions.Visible = this.optionsVisible;
			this.laFindOptions.Visible = !this.optionsVisible;
			this.pnFindOptions.Visible = !this.optionsVisible;
			this.btFindOptions.Text = (this.optionsVisible ? "-" : "+");
			this.laLookIn.Top = (this.IsReplace ? this.cbReplaceWith.Bottom : this.cbFindWhat.Bottom) + (int)(3f * num);
			this.cbLookIn.Top = (this.IsReplace ? this.cbReplaceWith.Bottom : this.cbFindWhat.Bottom) + (int)(19f * num);
			this.gbFindOptions.Top = this.cbLookIn.Bottom + (int)(14f * num);
			this.laFindOptions.Top = this.gbFindOptions.Top;
			this.pnFindOptions.Top = this.gbFindOptions.Top + (int)(6f * num);
			this.pnFindOptions.Left = this.laFindOptions.Right + (int)(2f * num);
			this.pnFindOptions.Width = base.Width - this.laFindOptions.Right - (int)(20f * num);
			this.btFindOptions.Top = this.gbFindOptions.Top - (int)(2f * num);
			this.pnButtons.Height = (this.IsReplace ? ((int)(65f * num)) : ((int)(36f * num)));
			base.Height = base.Height - base.ClientSize.Height + (this.gbFindOptions.Visible ? this.gbFindOptions.Bottom : (this.gbFindOptions.Top + (int)(12f * num))) + this.pnButtons.Height + (int)(2f * num);
		}
		private void DlgSearch_Load(object sender, EventArgs e)
		{
			base.ActiveControl = this.cbFindWhat;
			this.LoadFromResource();
			this.ResizeControls();
		}
		protected override void OnFontChanged(EventArgs e)
		{
			base.OnFontChanged(e);
			this.ResizeControls();
		}
		private void UpdateSearch()
		{
			int selectedIndex = this.cbLookIn.SelectedIndex;
			try
			{
				this.cbLookIn.Items.Clear();
				this.cbLookIn.Items.Add(StringConsts.FromCursorCaption);
				if (this.search != null && this.search.SearchGlobal)
				{
					this.cbLookIn.Items.Add(StringConsts.AllOpenDocumentsScope);
					this.cbLookIn.Items.Add(StringConsts.CurrentProjectScope);
				}
				this.cbLookIn.Items.Add(StringConsts.EntireScopeCaption.Replace("&", string.Empty));
				if (this.selectionEnabled)
				{
					this.cbLookIn.Items.Add(StringConsts.SelectionOnlyCaption.Replace("&", string.Empty));
				}
			}
			finally
			{
				this.cbLookIn.SelectedIndex = ((selectedIndex >= 0 && selectedIndex < this.cbLookIn.Items.Count) ? selectedIndex : 0);
			}
		}
		private string RemoveAmpersand(string str)
		{
			return str.Replace("&", string.Empty);
		}
		private void LoadFromResource()
		{
			this.laFindWhat.Text = StringConsts.FindWhatCaption;
			this.laReplaceWith.Text = StringConsts.ReplaceWithCaption;
			this.chbMatchCase.Text = StringConsts.MatchCaseCaption;
			this.chbMatchWholeWord.Text = StringConsts.MatchWholeWordCaption;
			this.chbSearchHiddenText.Text = StringConsts.SearchHiddenTextCaption;
			this.chbSearchUp.Text = StringConsts.SearchUpCaption;
			this.chbUseRegularExpressions.Text = StringConsts.UseRegularExpressionsCaption;
			this.chbPromptOnReplace.Text = StringConsts.PromptOnReplaceCaption;
			this.btFindNext.Text = StringConsts.FindNextCaption;
			this.btReplace.Text = StringConsts.ReplaceCaption + " ";
			this.tbUseFind.Text = StringConsts.DlgSearchCaption + " ";
			this.tbUseReplace.Text = this.RemoveAmpersand(StringConsts.ReplaceCaption);
			this.btReplaceAll.Text = StringConsts.ReplaceAllCaption;
			this.btMarkAll.Text = StringConsts.MarkAllCaption;
			this.gbFindOptions.Text = string.Format("    {0}", StringConsts.FindOptionsCaption);
			this.laFindOptions.Text = string.Format(StringConsts.FindOptionsCaption, new object[0]);
			this.laLookIn.Text = StringConsts.LookInCaption;
			this.Text = StringConsts.DlgSearchReplaceCaption;
			this.miSingleChar.Text = StringConsts.SingleCharCaption;
			this.miZeroOrMore.Text = StringConsts.ZeroOrMoreCaption;
			this.miOneOrMore.Text = StringConsts.OneOrMoreCaption;
			this.miBeginLine.Text = StringConsts.BeginLineCaption;
			this.miEndLine.Text = StringConsts.EndLineCaption;
			this.miLineBreak.Text = StringConsts.LineBreakCaption;
			this.miOneCharInSet.Text = StringConsts.OneCharInSetCaption;
			this.miOneCharNotInSet.Text = StringConsts.OneCharNotInSetCaption;
			this.miOr.Text = StringConsts.OrCaption;
			this.miEscape.Text = StringConsts.EscapeCaption;
			this.miTag.Text = StringConsts.TagCaption;
			this.miFindWhatText.Text = StringConsts.FindWhatTextCaption;
			this.miTaggedExpression1.Text = string.Format("${1} {0} {1}", StringConsts.TagExpressionCaption, 1);
			this.miTaggedExpression2.Text = string.Format("${1} {0} {1}", StringConsts.TagExpressionCaption, 2);
			this.miTaggedExpression3.Text = string.Format("${1} {0} {1}", StringConsts.TagExpressionCaption, 3);
			this.miTaggedExpression4.Text = string.Format("${1} {0} {1}", StringConsts.TagExpressionCaption, 4);
			this.miTaggedExpression5.Text = string.Format("${1} {0} {1}", StringConsts.TagExpressionCaption, 5);
			this.miTaggedExpression6.Text = string.Format("${1} {0} {1}", StringConsts.TagExpressionCaption, 6);
			this.miTaggedExpression7.Text = string.Format("${1} {0} {1}", StringConsts.TagExpressionCaption, 7);
			this.miTaggedExpression8.Text = string.Format("${1} {0} {1}", StringConsts.TagExpressionCaption, 8);
			this.miTaggedExpression9.Text = string.Format("${1} {0} {1}", StringConsts.TagExpressionCaption, 9);
		}
		private void btReplacePopup_Click(object sender, EventArgs e)
		{
			this.cmReplace.Show((Control)sender, new Point(0, 0));
		}
		private void miFindWhatText_Click(object sender, EventArgs e)
		{
			string text = ((MenuItem)sender).Text.Trim();
			int num = text.IndexOf(' ');
			if (num > 0)
			{
				text = text.Substring(0, num);
			}
			this.cbReplaceWith.Text = this.cbReplaceWith.Text + text;
		}
		private void UpdateSearchMode()
		{
			switch (this.cbLookIn.SelectedIndex)
			{
			case 1:
			case 2:
				this.SearchShared = (this.search != null && this.search.SearchGlobal);
				break;
			default:
				this.SearchShared = false;
				break;
			}
		}
		protected void ReplaceChanged()
		{
			this.laReplaceWith.Visible = this.isReplace;
			this.cbReplaceWith.Visible = this.isReplace;
			this.btReplacePopup.Visible = this.isReplace;
			this.btReplace.Visible = this.isReplace;
			this.btReplaceAll.Visible = this.isReplace;
			this.btMarkAll.Visible = !this.isReplace;
			this.btPopup.Enabled = this.chbUseRegularExpressions.Checked;
			this.btReplacePopup.Enabled = this.chbUseRegularExpressions.Checked;
			this.tbSearch.SelectedIndex = (this.isReplace ? 1 : 0);
			this.ResizeControls();
		}
		protected void ShowNotFound()
		{
			this.ShowNotFound(this.Text);
			this.cbFindWhat.Focus();
		}
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);
			if (this.cbFindWhat.Text == string.Empty && this.cbFindWhat.Items.Count > 0)
			{
				this.cbFindWhat.SelectedIndex = 0;
			}
		}
		protected virtual bool NeedReplaceCurrent(out Match match)
		{
			return this.SearchShared ? SearchManager.SharedSearch.NeedReplaceCurrent(out match) : this.Search.NeedReplaceCurrent(out match);
		}
		protected virtual bool ReplaceCurrent(string replaceWith, SearchOptions options, Match match)
		{
			return this.SearchShared ? SearchManager.SharedSearch.ReplaceCurrent(replaceWith, options, match) : this.Search.ReplaceCurrent(replaceWith, options, match);
		}
		protected virtual bool FindPrevious()
		{
			return this.SearchShared ? SearchManager.SharedSearch.FindPrevious() : this.Search.FindPrevious();
		}
		protected virtual bool FindNext()
		{
			return this.SearchShared ? SearchManager.SharedSearch.FindNext() : this.Search.FindNext();
		}
		protected virtual bool Find(string text, SearchOptions options, Regex expression)
		{
			return this.SearchShared ? SearchManager.SharedSearch.Find(this.Search, text, options, expression) : this.Search.Find(text, options, expression);
		}
		protected virtual int MarkAll(string text, SearchOptions options, Regex expression, bool clearPrevious)
		{
			return this.SearchShared ? SearchManager.SharedSearch.MarkAll(this.Search, text, options, expression, clearPrevious) : this.Search.MarkAll(text, options, expression, clearPrevious);
		}
		protected virtual bool ReplaceAll(string text, string replaceWith, SearchOptions options, Regex expression, out int count)
		{
			bool flag;
			return this.SearchShared ? SearchManager.SharedSearch.ReplaceAll(this.Search, text, replaceWith, options, expression, out count, out flag) : this.Search.ReplaceAll(text, replaceWith, options, expression, out count, out flag);
		}
		protected virtual void ShowNotFound(string caption)
		{
			if (this.SearchShared)
			{
				SearchManager.SharedSearch.ShowNotFound(this.Search, caption);
			}
			else
			{
				this.Search.ShowNotFound(caption);
			}
		}
		public void Init()
		{
			this.firstSearch = true;
			this.saveOptions = SearchOptions.None;
			this.saveText = string.Empty;
			this.UpdateSearch();
		}
		private void btClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void tbSearch_Selected(object sender, TabControlEventArgs e)
		{
			this.IsReplace = (this.tbSearch.SelectedIndex == 1);
		}
		private void tbUseReplace_Enter(object sender, EventArgs e)
		{
			if (this.cbFindWhat.CanFocus)
			{
				this.cbFindWhat.Focus();
			}
		}
		private void tbSearch_Enter(object sender, EventArgs e)
		{
			if (this.cbFindWhat.CanFocus)
			{
				this.cbFindWhat.Focus();
			}
		}
		private void DlgSearch_Shown(object sender, EventArgs e)
		{
			this.cbFindWhat.SelectAll();
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			this.components = new Container();
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(DlgSearch));
			this.chbPromptOnReplace = new CheckBox();
			this.chbSearchUp = new CheckBox();
			this.chbSearchHiddenText = new CheckBox();
			this.chbMatchWholeWord = new CheckBox();
			this.btReplacePopup = new Button();
			this.chbMatchCase = new CheckBox();
			this.chbUseRegularExpressions = new CheckBox();
			this.cmReplace = new ContextMenu();
			this.miFindWhatText = new MenuItem();
			this.miTaggedExpression1 = new MenuItem();
			this.miTaggedExpression2 = new MenuItem();
			this.miTaggedExpression3 = new MenuItem();
			this.miTaggedExpression4 = new MenuItem();
			this.miTaggedExpression5 = new MenuItem();
			this.miTaggedExpression6 = new MenuItem();
			this.miTaggedExpression7 = new MenuItem();
			this.miTaggedExpression8 = new MenuItem();
			this.miTaggedExpression9 = new MenuItem();
			this.miTag = new MenuItem();
			this.laFindWhat = new Label();
			this.cbReplaceWith = new ComboBox();
			this.laReplaceWith = new Label();
			this.miEscape = new MenuItem();
			this.btReplaceAll = new Button();
			this.btMarkAll = new Button();
			this.btReplace = new Button();
			this.btFindNext = new Button();
			this.cmFind = new ContextMenu();
			this.miSingleChar = new MenuItem();
			this.miZeroOrMore = new MenuItem();
			this.miOneOrMore = new MenuItem();
			this.menuItem4 = new MenuItem();
			this.miBeginLine = new MenuItem();
			this.miEndLine = new MenuItem();
			this.miLineBreak = new MenuItem();
			this.menuItem10 = new MenuItem();
			this.miOneCharInSet = new MenuItem();
			this.miOneCharNotInSet = new MenuItem();
			this.miOr = new MenuItem();
			this.btPopup = new Button();
			this.cbFindWhat = new ComboBox();
			this.pnButtons = new Panel();
			this.btClose = new Button();
			this.gbFindOptions = new GroupBox();
			this.btFindOptions = new Button();
			this.cbLookIn = new ComboBox();
			this.laLookIn = new Label();
			this.laFindOptions = new Label();
			this.pnFindOptions = new Panel();
			this.tbSearch = new TabControl();
			this.tbUseFind = new TabPage();
			this.tbUseReplace = new TabPage();
			this.imSearch = new ImageList(this.components);
			this.pnButtons.SuspendLayout();
			this.gbFindOptions.SuspendLayout();
			this.tbSearch.SuspendLayout();
			base.SuspendLayout();
			this.chbPromptOnReplace.FlatStyle = FlatStyle.System;
			this.chbPromptOnReplace.Location = new Point(8, 116);
			this.chbPromptOnReplace.Name = "chbPromptOnReplace";
			this.chbPromptOnReplace.Size = new Size(217, 25);
			this.chbPromptOnReplace.TabIndex = 16;
			this.chbPromptOnReplace.Text = "Prompt on replace";
			this.chbSearchUp.FlatStyle = FlatStyle.System;
			this.chbSearchUp.Location = new Point(8, 56);
			this.chbSearchUp.Name = "chbSearchUp";
			this.chbSearchUp.Size = new Size(217, 25);
			this.chbSearchUp.TabIndex = 13;
			this.chbSearchUp.Text = "Search &up";
			this.chbSearchHiddenText.FlatStyle = FlatStyle.System;
			this.chbSearchHiddenText.Location = new Point(8, 76);
			this.chbSearchHiddenText.Name = "chbSearchHiddenText";
			this.chbSearchHiddenText.Size = new Size(217, 25);
			this.chbSearchHiddenText.TabIndex = 14;
			this.chbSearchHiddenText.Text = "Search &hidden text";
			this.chbMatchWholeWord.FlatStyle = FlatStyle.System;
			this.chbMatchWholeWord.Location = new Point(8, 36);
			this.chbMatchWholeWord.Name = "chbMatchWholeWord";
			this.chbMatchWholeWord.Size = new Size(217, 25);
			this.chbMatchWholeWord.TabIndex = 12;
			this.chbMatchWholeWord.Text = "Match &whole word";
			this.btReplacePopup.BackColor = SystemColors.Control;
			this.btReplacePopup.FlatStyle = FlatStyle.System;
			this.btReplacePopup.ImageIndex = 0;
			this.btReplacePopup.Location = new Point(239, 90);
			this.btReplacePopup.Name = "btReplacePopup";
			this.btReplacePopup.Size = new Size(17, 20);
			this.btReplacePopup.TabIndex = 32;
			this.btReplacePopup.Text = ">";
			this.btReplacePopup.UseVisualStyleBackColor = false;
			this.btReplacePopup.Visible = false;
			this.btReplacePopup.Click += new EventHandler(this.btReplacePopup_Click);
			this.chbMatchCase.FlatStyle = FlatStyle.System;
			this.chbMatchCase.Location = new Point(8, 16);
			this.chbMatchCase.Name = "chbMatchCase";
			this.chbMatchCase.Size = new Size(217, 25);
			this.chbMatchCase.TabIndex = 11;
			this.chbMatchCase.Text = "Match &case";
			this.chbUseRegularExpressions.FlatStyle = FlatStyle.System;
			this.chbUseRegularExpressions.Location = new Point(8, 96);
			this.chbUseRegularExpressions.Name = "chbUseRegularExpressions";
			this.chbUseRegularExpressions.Size = new Size(217, 25);
			this.chbUseRegularExpressions.TabIndex = 15;
			this.chbUseRegularExpressions.Text = "Use &regular expressions";
			this.chbUseRegularExpressions.CheckedChanged += new EventHandler(this.chbUseRegularExpressions_Click);
			this.cmReplace.MenuItems.AddRange(new MenuItem[]
			{
				this.miFindWhatText,
				this.miTaggedExpression1,
				this.miTaggedExpression2,
				this.miTaggedExpression3,
				this.miTaggedExpression4,
				this.miTaggedExpression5,
				this.miTaggedExpression6,
				this.miTaggedExpression7,
				this.miTaggedExpression8,
				this.miTaggedExpression9
			});
			this.miFindWhatText.Index = 0;
			this.miFindWhatText.Text = "$0 Find What Text";
			this.miFindWhatText.Click += new EventHandler(this.miFindWhatText_Click);
			this.miTaggedExpression1.Index = 1;
			this.miTaggedExpression1.Text = "$1 Tagged Expression 1";
			this.miTaggedExpression1.Click += new EventHandler(this.miFindWhatText_Click);
			this.miTaggedExpression2.Index = 2;
			this.miTaggedExpression2.Text = "$2 Tagged Expression 2";
			this.miTaggedExpression2.Click += new EventHandler(this.miFindWhatText_Click);
			this.miTaggedExpression3.Index = 3;
			this.miTaggedExpression3.Text = "$3 Tagged Expression 3";
			this.miTaggedExpression3.Click += new EventHandler(this.miFindWhatText_Click);
			this.miTaggedExpression4.Index = 4;
			this.miTaggedExpression4.Text = "$4 Tagged Expression 4";
			this.miTaggedExpression4.Click += new EventHandler(this.miFindWhatText_Click);
			this.miTaggedExpression5.Index = 5;
			this.miTaggedExpression5.Text = "$5 Tagged Expression 5";
			this.miTaggedExpression5.Click += new EventHandler(this.miFindWhatText_Click);
			this.miTaggedExpression6.Index = 6;
			this.miTaggedExpression6.Text = "$6 Tagged Expression 6";
			this.miTaggedExpression6.Click += new EventHandler(this.miFindWhatText_Click);
			this.miTaggedExpression7.Index = 7;
			this.miTaggedExpression7.Text = "$7 Tagged Expression 7";
			this.miTaggedExpression7.Click += new EventHandler(this.miFindWhatText_Click);
			this.miTaggedExpression8.Index = 8;
			this.miTaggedExpression8.Text = "$8 Tagged Expression 8";
			this.miTaggedExpression8.Click += new EventHandler(this.miFindWhatText_Click);
			this.miTaggedExpression9.Index = 9;
			this.miTaggedExpression9.Text = "$9 Tagged Expression 9";
			this.miTaggedExpression9.Click += new EventHandler(this.miFindWhatText_Click);
			this.miTag.Index = 12;
			this.miTag.Text = "{} Tag expression";
			this.miTag.Click += new EventHandler(this.miBeginWord_Click);
			this.laFindWhat.AutoSize = true;
			this.laFindWhat.FlatStyle = FlatStyle.System;
			this.laFindWhat.Location = new Point(8, 33);
			this.laFindWhat.Name = "laFindWhat";
			this.laFindWhat.Size = new Size(56, 13);
			this.laFindWhat.TabIndex = 20;
			this.laFindWhat.Text = "Fi&nd what:";
			this.cbReplaceWith.Location = new Point(8, 90);
			this.cbReplaceWith.Name = "cbReplaceWith";
			this.cbReplaceWith.Size = new Size(225, 21);
			this.cbReplaceWith.TabIndex = 24;
			this.cbReplaceWith.Visible = false;
			this.laReplaceWith.AutoSize = true;
			this.laReplaceWith.FlatStyle = FlatStyle.System;
			this.laReplaceWith.Location = new Point(8, 74);
			this.laReplaceWith.Name = "laReplaceWith";
			this.laReplaceWith.Size = new Size(72, 13);
			this.laReplaceWith.TabIndex = 22;
			this.laReplaceWith.Text = "Re&place with:";
			this.laReplaceWith.Visible = false;
			this.miEscape.Index = 11;
			this.miEscape.Text = "\\ Escape Special Character";
			this.miEscape.Click += new EventHandler(this.miBeginWord_Click);
			this.btReplaceAll.FlatStyle = FlatStyle.System;
			this.btReplaceAll.Location = new Point(158, 35);
			this.btReplaceAll.Name = "btReplaceAll";
			this.btReplaceAll.Size = new Size(98, 23);
			this.btReplaceAll.TabIndex = 27;
			this.btReplaceAll.Text = "Replace &All";
			this.btReplaceAll.Visible = false;
			this.btReplaceAll.Click += new EventHandler(this.btReplaceAll_Click);
			this.btMarkAll.FlatStyle = FlatStyle.System;
			this.btMarkAll.Location = new Point(158, 8);
			this.btMarkAll.Name = "btMarkAll";
			this.btMarkAll.Size = new Size(98, 23);
			this.btMarkAll.TabIndex = 28;
			this.btMarkAll.Text = "Bookmark All";
			this.btMarkAll.Click += new EventHandler(this.btMarkAll_Click);
			this.btReplace.FlatStyle = FlatStyle.System;
			this.btReplace.ImageAlign = ContentAlignment.MiddleRight;
			this.btReplace.Location = new Point(158, 8);
			this.btReplace.Name = "btReplace";
			this.btReplace.Size = new Size(98, 23);
			this.btReplace.TabIndex = 26;
			this.btReplace.Text = "&Replace";
			this.btReplace.Visible = false;
			this.btReplace.Click += new EventHandler(this.btReplace_Click);
			this.btFindNext.FlatStyle = FlatStyle.System;
			this.btFindNext.Location = new Point(54, 8);
			this.btFindNext.Name = "btFindNext";
			this.btFindNext.Size = new Size(98, 23);
			this.btFindNext.TabIndex = 25;
			this.btFindNext.Text = "&Find Next";
			this.btFindNext.Click += new EventHandler(this.btFindNext_Click);
			this.cmFind.MenuItems.AddRange(new MenuItem[]
			{
				this.miSingleChar,
				this.miZeroOrMore,
				this.miOneOrMore,
				this.menuItem4,
				this.miBeginLine,
				this.miEndLine,
				this.miLineBreak,
				this.menuItem10,
				this.miOneCharInSet,
				this.miOneCharNotInSet,
				this.miOr,
				this.miEscape,
				this.miTag
			});
			this.miSingleChar.Index = 0;
			this.miSingleChar.Text = ". Any single character";
			this.miSingleChar.Click += new EventHandler(this.miBeginWord_Click);
			this.miZeroOrMore.Index = 1;
			this.miZeroOrMore.Text = "* Zero or more";
			this.miZeroOrMore.Click += new EventHandler(this.miBeginWord_Click);
			this.miOneOrMore.Index = 2;
			this.miOneOrMore.Text = "+ One or more";
			this.miOneOrMore.Click += new EventHandler(this.miBeginWord_Click);
			this.menuItem4.Index = 3;
			this.menuItem4.Text = "-";
			this.miBeginLine.Index = 4;
			this.miBeginLine.Text = "^ Beginning of line";
			this.miBeginLine.Click += new EventHandler(this.miBeginWord_Click);
			this.miEndLine.Index = 5;
			this.miEndLine.Text = "$ End of line";
			this.miEndLine.Click += new EventHandler(this.miBeginWord_Click);
			this.miLineBreak.Index = 6;
			this.miLineBreak.Text = "\\n Line break";
			this.miLineBreak.Click += new EventHandler(this.miBeginWord_Click);
			this.menuItem10.Index = 7;
			this.menuItem10.Text = "-";
			this.miOneCharInSet.Index = 8;
			this.miOneCharInSet.Text = "[] Any one character in the set";
			this.miOneCharInSet.Click += new EventHandler(this.miBeginWord_Click);
			this.miOneCharNotInSet.Index = 9;
			this.miOneCharNotInSet.Text = "[^] Any one character not in the set";
			this.miOneCharNotInSet.Click += new EventHandler(this.miBeginWord_Click);
			this.miOr.Index = 10;
			this.miOr.Text = "| Or";
			this.miOr.Click += new EventHandler(this.miBeginWord_Click);
			this.btPopup.BackColor = SystemColors.Control;
			this.btPopup.FlatStyle = FlatStyle.System;
			this.btPopup.ImageIndex = 0;
			this.btPopup.Location = new Point(239, 50);
			this.btPopup.Name = "btPopup";
			this.btPopup.Size = new Size(17, 20);
			this.btPopup.TabIndex = 23;
			this.btPopup.Text = ">";
			this.btPopup.UseVisualStyleBackColor = false;
			this.btPopup.Click += new EventHandler(this.btPopup_Click);
			this.cbFindWhat.Location = new Point(8, 49);
			this.cbFindWhat.Name = "cbFindWhat";
			this.cbFindWhat.Size = new Size(225, 21);
			this.cbFindWhat.TabIndex = 21;
			this.pnButtons.Controls.Add(this.btClose);
			this.pnButtons.Controls.Add(this.btFindNext);
			this.pnButtons.Controls.Add(this.btReplace);
			this.pnButtons.Controls.Add(this.btReplaceAll);
			this.pnButtons.Controls.Add(this.btMarkAll);
			this.pnButtons.Dock = DockStyle.Bottom;
			this.pnButtons.Location = new Point(0, 313);
			this.pnButtons.Name = "pnButtons";
			this.pnButtons.Size = new Size(267, 65);
			this.pnButtons.TabIndex = 34;
			this.btClose.DialogResult = DialogResult.Cancel;
			this.btClose.FlatStyle = FlatStyle.System;
			this.btClose.Location = new Point(192, 237);
			this.btClose.Name = "btClose";
			this.btClose.Size = new Size(98, 23);
			this.btClose.TabIndex = 29;
			this.btClose.Text = "Close";
			this.btClose.Click += new EventHandler(this.btClose_Click);
			this.gbFindOptions.Controls.Add(this.chbPromptOnReplace);
			this.gbFindOptions.Controls.Add(this.chbMatchCase);
			this.gbFindOptions.Controls.Add(this.chbMatchWholeWord);
			this.gbFindOptions.Controls.Add(this.chbUseRegularExpressions);
			this.gbFindOptions.Controls.Add(this.chbSearchUp);
			this.gbFindOptions.Controls.Add(this.chbSearchHiddenText);
			this.gbFindOptions.Location = new Point(8, 165);
			this.gbFindOptions.Name = "gbFindOptions";
			this.gbFindOptions.Size = new Size(248, 142);
			this.gbFindOptions.TabIndex = 35;
			this.gbFindOptions.TabStop = false;
			this.gbFindOptions.Text = "    Find Options";
			this.btFindOptions.BackColor = SystemColors.Control;
			this.btFindOptions.FlatStyle = FlatStyle.System;
			this.btFindOptions.Font = new Font("Symbol", 6.75f, FontStyle.Regular, GraphicsUnit.Point, 204);
			this.btFindOptions.ImageIndex = 0;
			this.btFindOptions.Location = new Point(8, 157);
			this.btFindOptions.Name = "btFindOptions";
			this.btFindOptions.Size = new Size(18, 18);
			this.btFindOptions.TabIndex = 39;
			this.btFindOptions.Text = "-";
			this.btFindOptions.UseVisualStyleBackColor = false;
			this.btFindOptions.Click += new EventHandler(this.btFindOptions_Click);
			this.cbLookIn.DropDownStyle = ComboBoxStyle.DropDownList;
			this.cbLookIn.FormattingEnabled = true;
			this.cbLookIn.Location = new Point(8, 130);
			this.cbLookIn.Name = "cbLookIn";
			this.cbLookIn.Size = new Size(248, 21);
			this.cbLookIn.TabIndex = 37;
			this.laLookIn.AutoSize = true;
			this.laLookIn.FlatStyle = FlatStyle.System;
			this.laLookIn.Location = new Point(8, 114);
			this.laLookIn.Name = "laLookIn";
			this.laLookIn.Size = new Size(46, 13);
			this.laLookIn.TabIndex = 38;
			this.laLookIn.Text = "Look In:";
			this.laFindOptions.AutoSize = true;
			this.laFindOptions.Location = new Point(26, 154);
			this.laFindOptions.Name = "laFindOptions";
			this.laFindOptions.Size = new Size(66, 13);
			this.laFindOptions.TabIndex = 40;
			this.laFindOptions.Text = "Find Options";
			this.laFindOptions.Visible = false;
			this.pnFindOptions.BackColor = SystemColors.ScrollBar;
			this.pnFindOptions.Location = new Point(90, 157);
			this.pnFindOptions.Name = "pnFindOptions";
			this.pnFindOptions.Size = new Size(164, 1);
			this.pnFindOptions.TabIndex = 41;
			this.pnFindOptions.Visible = false;
			this.tbSearch.Appearance = TabAppearance.FlatButtons;
			this.tbSearch.Controls.Add(this.tbUseFind);
			this.tbSearch.Controls.Add(this.tbUseReplace);
			this.tbSearch.Dock = DockStyle.Top;
			this.tbSearch.ImageList = this.imSearch;
			this.tbSearch.ItemSize = new Size(80, 22);
			this.tbSearch.Location = new Point(0, 0);
			this.tbSearch.Name = "tbSearch";
			this.tbSearch.SelectedIndex = 0;
			this.tbSearch.Size = new Size(267, 24);
			this.tbSearch.TabIndex = 17;
			this.tbSearch.Selected += new TabControlEventHandler(this.tbSearch_Selected);
			this.tbSearch.Enter += new EventHandler(this.tbSearch_Enter);
			this.tbUseFind.ImageIndex = 0;
			this.tbUseFind.Location = new Point(4, 26);
			this.tbUseFind.Name = "tbUseFind";
			this.tbUseFind.Padding = new Padding(3);
			this.tbUseFind.Size = new Size(259, 0);
			this.tbUseFind.TabIndex = 0;
			this.tbUseFind.Text = "Find";
			this.tbUseFind.UseVisualStyleBackColor = true;
			this.tbUseReplace.ImageIndex = 1;
			this.tbUseReplace.Location = new Point(4, 26);
			this.tbUseReplace.Name = "tbUseReplace";
			this.tbUseReplace.Padding = new Padding(3);
			this.tbUseReplace.Size = new Size(259, 0);
			this.tbUseReplace.TabIndex = 1;
			this.tbUseReplace.Text = "Replace";
			this.tbUseReplace.UseVisualStyleBackColor = true;
			this.tbUseReplace.Enter += new EventHandler(this.tbUseReplace_Enter);
			this.imSearch.ImageStream = (ImageListStreamer)componentResourceManager.GetObject("imSearch.ImageStream");
			this.imSearch.TransparentColor = Color.Fuchsia;
			this.imSearch.Images.SetKeyName(0, "UseFind1.bmp");
			this.imSearch.Images.SetKeyName(1, "UseReplace1.bmp");
			base.AcceptButton = this.btFindNext;
			base.AutoScaleDimensions = new SizeF(6f, 13f);
			base.AutoScaleMode = AutoScaleMode.Font;
			base.CancelButton = this.btClose;
			base.ClientSize = new Size(267, 378);
			base.Controls.Add(this.tbSearch);
			base.Controls.Add(this.pnFindOptions);
			base.Controls.Add(this.laFindOptions);
			base.Controls.Add(this.btFindOptions);
			base.Controls.Add(this.laLookIn);
			base.Controls.Add(this.cbLookIn);
			base.Controls.Add(this.gbFindOptions);
			base.Controls.Add(this.pnButtons);
			base.Controls.Add(this.btReplacePopup);
			base.Controls.Add(this.laFindWhat);
			base.Controls.Add(this.cbReplaceWith);
			base.Controls.Add(this.laReplaceWith);
			base.Controls.Add(this.btPopup);
			base.Controls.Add(this.cbFindWhat);
			base.FormBorderStyle = FormBorderStyle.FixedToolWindow;
			base.Name = "DlgSearch";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "Find";
			base.Load += new EventHandler(this.DlgSearch_Load);
			base.Shown += new EventHandler(this.DlgSearch_Shown);
			this.pnButtons.ResumeLayout(false);
			this.gbFindOptions.ResumeLayout(false);
			this.tbSearch.ResumeLayout(false);
			base.ResumeLayout(false);
			base.PerformLayout();
		}
	}
}
